<template>
  <div class="container">
    <div class="container-title">
      <p>项目公海</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>招商管理</el-breadcrumb-item>
        <el-breadcrumb-item>项目管理</el-breadcrumb-item>
        <el-breadcrumb-item>项目公海</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search-box">
      <el-form ref="form" :model="searchData">
        <el-form-item
          ><el-input
            v-model="searchData.projectName"
            placeholder="项目名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="searchData.business"
            placeholder="行业大类"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="searchData.sourceWay"
            placeholder="来源方式"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="searchData.date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="success"
            @click="onSearch"
            icon="el-icon-search"
            style="background-color: #0bb197"
            >查询</el-button
          ><el-button @click="onReset" icon="el-icon-refresh" class="reset"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格 -->
    <div class="data-list">
      <div class="data-list-title">
        <span>查询结果列表</span>
        <div>
          <el-button
            type="success"
            @click="addDialog = true"
            style="background-color: #0bb197"
            >新增</el-button
          >
        </div>
      </div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="projectName" label="项目名称" align="center">
        </el-table-column>
        <el-table-column
          prop="area"
          label="所属地区"
          align="center"
          width="200"
        >
        </el-table-column>
        <el-table-column prop="business" label="行业大类" align="center">
        </el-table-column>
        <el-table-column
          prop="registeredCapital"
          label="注册资本（万）"
          align="center"
          width="150"
        >
        </el-table-column>
        <el-table-column prop="contact" label="联系人员" align="center">
        </el-table-column>
        <el-table-column prop="contactTel" label="联系方式" align="center">
        </el-table-column>
        <el-table-column prop="sourceWay" label="来源方式" align="center">
        </el-table-column>
        <el-table-column
          prop="creationTime"
          label="创建时间"
          align="center"
          width="200"
        >
          <template slot-scope="scope">
            <span>{{ timeTrans(scope.row.creationTime, 1) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="state" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0">意向登记</span>
            <span v-if="scope.row.status == 1">意向协定</span>
            <span v-if="scope.row.status == 2">合同签批</span>
            <span v-if="scope.row.status == 3">企业入驻</span>
            <span v-if="scope.row.status == 4">项目关闭</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-button @click="see(scope.row)" type="text" size="small"
              >查看</el-button
            >
            <el-button @click="editOpen(scope.row)" type="text" size="small"
              >编辑</el-button
            >
          </template></el-table-column
        >
      </el-table>
      <!-- 页码 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :background="true"
      >
      </el-pagination>
      <!-- 详情的弹出框 -->
      <!-- 查看 -->
      <div class="detail">
        <el-dialog title="详情信息" :visible.sync="seeDialog">
          <el-form :model="seeData">
            <div>
              <el-form-item label="来源方式" :label-width="formLabelWidth">
                <span>{{ seeData.sourceWay }}</span>
              </el-form-item>
              <el-form-item label="项目名称" :label-width="formLabelWidth">
                <span>{{ seeData.projectName }}</span>
              </el-form-item>
              <el-form-item label="企业状态" :label-width="formLabelWidth">
                <span>{{ seeData.companyState }}</span>
              </el-form-item>
              <el-form-item label="企业所属地区" :label-width="formLabelWidth">
                <span>{{ seeData.area }}</span>
              </el-form-item>
              <el-form-item label="企业联系人" :label-width="formLabelWidth">
                <span>{{ seeData.contact }} </span>
              </el-form-item>
              <el-form-item label="企业规模" :label-width="formLabelWidth">
                <span>{{ seeData.companyScale }} </span>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="来源类型" :label-width="formLabelWidth">
                <span>{{ seeData.sourceType }}</span>
              </el-form-item>
              <el-form-item label="企业名称" :label-width="formLabelWidth">
                <span>{{ seeData.companyName }}</span>
              </el-form-item>
              <el-form-item label="行业大类" :label-width="formLabelWidth">
                <span>{{ seeData.business }}</span>
              </el-form-item>
              <el-form-item label="详细地址" :label-width="formLabelWidth">
                <span> {{ seeData.address }}</span>
              </el-form-item>
              <el-form-item label="联系电话" :label-width="formLabelWidth">
                <span>{{ seeData.contactTel }} </span>
              </el-form-item>
              <el-form-item label="注册资本" :label-width="formLabelWidth">
                <span>{{ seeData.registeredCapital }} </span>
              </el-form-item>
            </div>
          </el-form>
        </el-dialog>
      </div>
      <!-- 编辑 -->
      <div class="editDia">
        <el-dialog title="新增兑换" :visible.sync="editDialog">
          <el-form :model="editData">
            <div>
              <el-form-item label="项目名称" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.projectName"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="来源方式" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.sourceWay"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业状态" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.companyState"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业所属地区" :label-width="formLabelWidth">
                <el-input v-model="editData.area" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="企业联系人" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.contact"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业规模" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.companyScale"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="来源类型" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.sourceType"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业名称" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.companyName"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="行业大类" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.business"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="详细地址" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.address"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="联系人电话" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.contactTel"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="注册资本" :label-width="formLabelWidth">
                <el-input
                  v-model="editData.registeredCapital"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </div>
          </el-form>

          <div slot="footer" class="dialog-footer">
            <el-button @click="editDialog = false">取 消</el-button>
            <el-button class="footer" type="primary" @click="edit"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
      <!-- 新增 -->
      <div class="addDia">
        <el-dialog title="新增兑换" :visible.sync="addDialog">
          <el-form :model="addData">
            <div>
              <el-form-item label="项目名称" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.projectName"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="来源方式" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.sourceWay"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业状态" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.companyState"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业所属地区" :label-width="formLabelWidth">
                <el-input v-model="addData.area" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="企业联系人" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.contact"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业规模" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.companyScale"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="来源类型" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.sourceType"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业名称" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.companyName"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="行业大类" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.business"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="详细地址" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.address"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="联系人电话" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.contactTel"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="注册资本" :label-width="formLabelWidth">
                <el-input
                  v-model="addData.registeredCapital"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </div>
          </el-form>

          <div slot="footer" class="dialog-footer">
            <el-button @click="addDialog = false">取 消</el-button>
            <el-button class="footer"  type="primary" @click="add" 
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import time from "../utils/time";
export default {
  mixins: [time],
  data: function () {
    return {
      tableData: [],
      seeDialog: false,
      editDialog: false,
      editData: {
        address: "",
        area: "",
        business: 0,
        businessChildCoding: "",
        companyName: "",
        companyScale: "",
        companyState: 0,
        contact: "",
        contactTel: "",
        creationTime: "",
        id: 0,
        projectName: "",
        registeredCapital: 0,
        remark: "",
        sourceType: 0,
        sourceWay: "",
        state: 0,
      },
      seeData: {},
      currentPage4: 1,
      addDialog: false,
      addData: {
        address: "",
        area: "",
        business: 0,
        businessChildCoding: "",
        companyName: "",
        companyScale: "",
        companyState: 0,
        contact: "",
        contactTel: "",
        creationTime: "",
        id: 0,
        projectName: "",
        registeredCapital: 0,
        remark: "",
        sourceType: 0,
        sourceWay: "",
        state: 0,
      },
      pageSize: 5,
      pageNum: 1,
      total: 0,
      formLabelWidth: "120px",
      options: [
        {
          value: "0",
          label: "已完成",
        },
        {
          value: "1",
          label: "发布中",
        },
      ],
      searchData: {
        projectName: "",
        date: [],
        business: "",
        sourceWay: "",
      },
    };
  },
  methods: {
    //页码
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getData();
    },
    getData: function () {
      this.$axios({
        url: "/smart/project/list/" + this.pageNum + "/" + this.pageSize,
        method: "get",
      }).then(({ data }) => {
        if (data.code == "00000") {
          console.log("hh", data.data);
          this.tableData = data.data.list;
          this.total = data.data.total;
        } else {
          this.$message.error("加载失败");
        }
      });
    },
    onSearch: function () {
      this.$axios({
        url: "/smart/project/getList",
        method: "post",
        data: {
          projectName: this.searchData.projectName,
          business: this.searchData.business,
          sourceWay: this.searchData.sourceWay,
          startTime: this.searchData.date[0],
          endTime: this.searchData.date[1],
        },
        params:{
          pageSize:this.pageSize,
         pageNumber:this.pageNum,
        }
      }).then(({data})=>{
        if(data.code=='00000'){
          this.tableData=data.data;
          this.total=data.data.total
        }else{
          this.$message.error("查询失败")
        }
      })
    },
    onReset: function () {
       this.searchData.projectName='',
       this.searchData.business='',
       this.searchData.sourceWay='',
       this.searchData.date=[],
       this.pageNum=1;
       this.getData();
    },

    add: function () {
      this.$axios({
        url: "/smart/project/add",
        method: "post",
        data: this.addData,
      }).then(({ data }) => {
        if (data.code == "00000") {
          this.addDialog = false;
          this.$message.success("添加成功");
          this.getData();
          this.addData = {};
        } else {
          this.$message.error("添加失败");
        }
      });
    },
    see(row) {
      this.seeDialog = true;
      this.$axios({
        url: "/smart/project/queryById/" + row.id,
        method: "get",
      }).then(({ data }) => {
        if ((data.code = "00000")) {
          this.seeData = data.data;
        } else {
          this.$message.error("查询失败");
        }
      });
    },
    editOpen(row) {
      this.editDialog = true;
      this.$axios({
        url: "/smart/project/queryById/" + row.id,
        method: "get",
      }).then(({ data }) => {
        if (data.code == "00000") {
          this.editData = data.data;
        }
      });
    },
    edit: function (row) {
      this.$axios({
        url: "/smart/integral-type/edit",
        method: "put",
        data: {
          id: this.editData.id,
          projectName: this.editData.projectName,
          sourceWay: this.editData.sourceWay,
          companyState: this.editData.companyState,
          area: this.editData.area,
          contact: this.editData.contact,
          companyScale: this.editData.companyScale,
          sourceType: this.editData.sourceType,
          companyName: this.editData.companyName,
          business: this.editData.business,
          address: this.editData.address,
          contactTel: this.editData.contactTel,
          registeredCapital: this.editData.registeredCapital,
        },
      }).then(({ data }) => {
        if (data.code == "00000") {
          this.editDialog = false;
          this.getData();
          this.$message.success("修改成功！");
        } else {
          this.$message.error("修改失败！");
        }
      });
    },
  },

  mounted: function () {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  .container-title {
    width: 98%;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    p {
      color: #333333;
      font-size: 16px;
      font-weight: 400;
      font-family: "Arial Normal", "Arial";
    }
    .el-breadcrumb-item {
      color: rgba(148, 148, 148, 0.898039215686275);
      font-size: 12px;
      font-weight: 400;
      font-family: "Arial Normal", "Arial";
    }
  }
  .search-box {
    width: 98%;
    height: 80px;
    background: #ffffff;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border: 1px solid #ffffff;
    border-radius: 5px;
    .el-form {
      width: 98%;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .el-form-item {
        margin-left: 10px;
        margin-bottom: 0;
        .el-select {
          width: 155px;
        }
        .el-button {
          margin: 10px;
        }
        .reset {
          background-color: white;
          color: #c0c4cc;
          border: 1px solid #c0c4cc;
        }
        .reset:hover {
          color: #0bb197;
        }
      }
      .block {
        margin-left: 10px;
      }
      .el-date-editor--datetimerange.el-input__inner {
        width: 310px;
      }
    }
  }
  .footer{
  background: #0bb197;
}
  .data-list {
    width: 98%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    margin-top: 20px;
    .data-list-title {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        height: 16px;
        font-family: "Arial Normal", "Arial";
        font-weight: 700;
        font-style: normal;
        font-size: 13px;
        color: #3c4145;
      }
    }
    .el-table {
      flex: 1;
      .el-button {
        color: #0bb197;
      }
    }
    .el-pagination {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
    .addBox {
      width: 100%;
      display: flex;
      justify-content: space-evenly;
    }
  }
}
.el-form {
  display: flex;
  justify-content: space-between;
}
</style>
<style lang="less">
.el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #0bb197;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #0bb197;
  color: #fff;
}
</style>
